<template>
  <div id="index">
    <div class="app-container"
      id="container">
      <el-form ref="form"
        :model="form"
        :rules="rules"
        label-width="120px"
        label-position="right">
        <div class="product-div">
          <div class="product-header big_title_style">
            基本信息
          </div>
          <el-form-item label="等级名称"
            prop="levelName">
            <el-input show-word-limit
              maxlength="10"
              style="width: 220px;"
              v-model="form.levelName"
              placeholder="输入等级名称" />
          </el-form-item>

          <el-form-item label="客户等级"
            prop="customerGrade">
            <el-select v-model="form.customerGrade"
              placeholder="请选择等级"
              clearable
              size="small">
              <el-option v-for="dict in gradeLevelOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
                :value="dict.dictValue"
                :disabled="dict.disabled" />
            </el-select>
          </el-form-item>

          <el-form-item label="级别图标">
            <div style="height: 110px;overflow: hidden">
              <imageUpload v-model="form.levelIcon"
                :msg="'图片宽高建议 100*100，大小2M内。'" />
            </div>
          </el-form-item>


        </div>

        <div class="product-div-two">
          <div class="product-header big_title_style">
            会员权益
          </div>
          <el-form-item label="权益">
            <div v-for="(item, index) in hash">
              <el-checkbox style="display: block"
                :label="item.privleageShowName"
                :key="index"
                :checked="item.privilegeStatus"
                @change="(val) => privilege(val, item, index, hash)">
                <span>{{ item.privleageShowName }}</span>
                <div style="display: inline-block; margin-left: 10px"
                  v-if="item.privilegeStatus">
                  <el-input v-model="item.privilegeValue"
                    size="small"
                    style="width: 220px"
                    placeholder="填写权益值"
                    @keyup.enter="search"
                    @input="search">
                  </el-input>
                  <span class="Unitdiv"
                    v-if="item.platformUnit!=null && item.platformUnit!=''">
                    {{ item.platformUnit }}
                  </span>
                </div>
              </el-checkbox>
            </div>

          </el-form-item>
        </div>
        <el-row style="height: 80px;">
        </el-row>
      </el-form>
      <div class="dw">
        <el-button @click="Formcancel">返回</el-button>
        <el-button type="primary"
          @click="submitForm">确 定</el-button>
      </div>

    </div>
  </div>

</template>

<script>
import {
  getLevelInfo,
  UpdateStartStatus,
  levelInfoDetail,
  delLevel,
  saveLevelPrivileageInfo,
  UpdateLevelPrivileageInfo,
  PrivileageInfo, getLevelByid
} from '@/api/customer/level'
import {
  getUploadToken
} from '@/api/monitor/file'
import Vue from 'vue'
import selGift from '@/components/Activity/selGift'
import selCoupon from '@/components/Activity/selCoupon'
import ImageUpload from '@/components/ImageUpload/levelImage'


import commodityItem from "@/components/Activity/commodityItem";
import commodityTab from "@/components/Activity/commodityTab";
import commodityCard from "@/components/Activity/commodityCard";


//验证手机号
let checkPrivilege = (rule, value, callback) => {
  let reg = /^((0\.[1-9]{1})|(([1-9]{1})(\.\d{1})?))$/
  if (!reg.test(value)) {
    callback(new Error('请输入整数或小数后一位'))
  } else {
    callback()
  }
}

let poins = (rule, value, callback) => {
  const reg = /^\d*\.{0,1}\d{0,1}$/
  if (!value && Number(value) != 0) {
    callback(new Error('请输入比例'))
  } else if (!Number(value) && Number(value) != 0) {
    callback(new Error('请输入数字值'))
  } else {
    if (reg.test(value)) {
      callback()
    } else {
      callback(new Error('小数点后最多只能输入一位'))
    }
  }
}

let perfor = (rule, value, callback) => {
  console.log(value)
  const reg = /^\d*\.{0,1}\d{0,1}$/
  if (!value && Number(value) != 0) {
    callback(new Error('请输入业绩'))
  } else if (!Number(value) && Number(value) != 0) {
    callback(new Error('请输入数字值'))
  } else {
    if (reg.test(value)) {
      callback()
    } else {
      callback(new Error('小数点后最多只能输入一位'))
    }
  }
}

let scoreAndFans = (rule, value, callback) => {
  const reg = /^[0-9]*$/
  if (!value && value != 0) {
    callback(new Error('请输入内容'))
  } else {
    if (reg.test(value)) {
      callback()
    } else {
      callback(new Error('请输入整数'))
    }
  }
}

export default {
  name: 'freePatternUpdate',
  components: {
    selGift,
    ImageUpload,
    selCoupon, commodityItem, commodityTab, commodityCard
  },
  props: {},
  data () {
    return {
      openProductUpdate: false,
      productListUpdate: [],
      openServiceCardUpdate: false,
      serviceCardListUpdate: [],
      openServiceItemUpdate: false,
      serviceItemListUpdate: [],
      openCUpdate: false,
      infoList2Update: [],
      openProduct: false,
      product: false,
      productList: [],
      openServiceCard: false,
      serviceCard: false,
      serviceCardList: [],
      openServiceItem: false,
      serviceItem: false,
      serviceItemList: [],
      gradeLevelOptions: [],
      openR: false,
      openC: false,
      levelColor: '',
      isshow: false,
      coupon: false,
      Giftgiving: false,
      listPrivilegedatas: [],
      listPrivilegedata: [],
      //赠送信息数组
      giveInfo: [],
      hashs: [],
      hash: [],
      loadingmore: 1,
      loadingmore2: 1,
      // 是否显示弹出层
      openE: false,
      // 弹出层标题
      title: '',
      //默认显示条数
      cou: 3,
      giftsNumber: '',
      couponNumber: '',
      infoList: [],
      infoList2: [],
      privilegeUid: '',
      isshow2: false,
      property: [],
      selUids: [],
      selList: [],
      levelPrivileageGives: [],
      titleg: '',
      openg: false,
      openg2: false,
      isIndeterminate: false,
      inputone: '',
      listPrivilege: null,
      bgcolor: '#87CEEB',
      itemcolor: '',
      caedFace: '0',
      visible: false,
      previewImg: '',
      uploadImgUrl: 'https://upload-z2.qiniup.com',
      upload_domain: '',
      uploadData: {
        token: '',
        key: ''
      },
      show: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        customerGrade: [
          {
            required: true,
            message: '请选择等级',
            trigger: 'blur'
          }
        ],
        ShowName: [{
          required: true,
          message: '请输入内容',
          trigger: 'blur'
        }],
        levelName: [{
          required: true,
          message: '请输入内容',
          trigger: 'blur'
        }],


        fansNumber: [{
          required: true,
          validator: scoreAndFans,
          trigger: 'blur'
        }],
        performance: [{
          required: true,
          validator: perfor,
          trigger: 'blur'
        }]
      },
      checkExceptRisk: []
    }
  },
  created () {

    let $this = this
    var levelId = $this.$route.params && $this.$route.params.levelId
    getLevelByid(levelId).then((response) => {
      this.gradeLevelOptions = response.data;
    });
    if (levelId != null) {
      levelInfoDetail(levelId).then((response) => {
        //console.log(response.customerLevel, '回显数据')
        this.form = response.customerLevel
        this.bgcolor = this.form.levelColor
        this.openE = true
        this.title = '修改客户等级'
        this.hash = []
        this.listPrivilegedata = []
        let giveobjs = new Array()
        let giveobjs2 = new Array()
        let giveobjs3 = new Array()
        let giveobjs4 = new Array()
        let giveobjs5 = new Array()
        let giveobjs6 = new Array()
        let giveobjs7 = new Array()
        let giveobjs8 = new Array()
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].levelPrivileageGives != null) {
            let giveList = this.form.customerLevelPrivleageVos[i].levelPrivileageGives
            giveList.forEach((item) => {
              let giveobj = new Object()
              if (item.giveType == 'coupon') {
                giveobj.couponName = item.giveName
                giveobj.couponUid = item.giveGiftId
                giveobj.couponNumber = item.giveNumber
                giveobj.stock = item.giveSumNumber
                giveobjs.push(giveobj)
              } else if (item.giveType == 'couponUpdate') {
                giveobj.couponName = item.giveName
                giveobj.couponUid = item.giveGiftId
                giveobj.couponNumber = item.giveNumber
                giveobj.stock = item.giveSumNumber
                giveobjs2.push(giveobj)
              } else if (item.giveType == 'good') {
                giveobj.productName = item.giveName
                giveobj.productUid = item.giveGiftId
                giveobj.productNumber = item.giveNumber
                giveobj.stockNumber = item.giveSumNumber
                giveobjs3.push(giveobj)
              } else if (item.giveType == 'goodUpdate') {
                giveobj.productName = item.giveName
                giveobj.productUid = item.giveGiftId
                giveobj.productNumber = item.giveNumber
                giveobj.stockNumber = item.giveSumNumber
                giveobjs4.push(giveobj)
              } else if (item.giveType == 'proboxCard') {
                giveobj.cardName = item.giveName
                giveobj.cardId = item.giveGiftId
                giveobj.serviceCardNumber = item.giveNumber
                giveobjs5.push(giveobj)
              } else if (item.giveType == 'proboxCardUpdate') {
                giveobj.cardName = item.giveName
                giveobj.cardId = item.giveGiftId
                giveobj.serviceCardNumber = item.giveNumber
                giveobjs6.push(giveobj)
              } else if (item.giveType == 'item') {
                giveobj.itemName = item.giveName
                giveobj.itemId = item.giveGiftId
                giveobj.itemNumber = item.giveNumber
                giveobjs7.push(giveobj)
              } else if (item.giveType == 'itemUpdate') {
                giveobj.itemName = item.giveName
                giveobj.itemId = item.giveGiftId
                giveobj.itemNumber = item.giveNumber
                giveobjs8.push(giveobj)
              }

            })
            this.infoList2 = giveobjs
            this.infoList2Update = giveobjs2
            this.productList = giveobjs3
            this.productListUpdate = giveobjs4
            this.serviceCardList = giveobjs5
            this.serviceCardListUpdate = giveobjs6
            this.serviceItemList = giveobjs7
            this.serviceItemListUpdate = giveobjs8
          }

        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          this.checkExceptRisk.push(this.form.customerLevelPrivleageVos[i])
        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 0) {
            this.hash.push(this.form.customerLevelPrivleageVos[i])
          }
        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 1) {
            this.listPrivilegedata.push(this.form.customerLevelPrivleageVos[i])
          }
        }

      })
    } else {
      this.getPrivileageInfo()
    }
  },
  methods: {
    //升级优惠券
    addcouponUpdate () {
      this.$forceUpdate()
      this.openCUpdate = true
      this.$nextTick(() => {
        this.$refs['selTable2Update'][0].greet2(this.infoList2Update)
      })
    },
    multipleSelection2Update (data) {
      this.openCUpdate = false
      this.infoList2Update = data
      this.infoList2Update.forEach(i => {
        this.$set(i, 'couponNumber', 1)
      })
    },
    handleDeleteser2Update (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.infoList2Update.splice(val, 1)
      })
    },
    // 升级商品
    addProductUpdate () {
      this.$forceUpdate()
      this.openProductUpdate = true
      this.$nextTick(() => {
        this.$refs['selTableProductUpdate'][0].greet(this.productListUpdate)
      })
    },
    multipleSelectionProductUpdate (data) {
      this.openProductUpdate = false
      this.productListUpdate = data
      this.productListUpdate.forEach(i => {
        this.$set(i, 'productNumber', 1)
      })
    },
    handleDeleteserProductUpdate (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.productListUpdate.splice(val, 1)
      })
    },
    // 升级套餐卡
    addServiceCardUpdate () {
      this.$forceUpdate()
      this.openServiceCardUpdate = true
      this.$nextTick(() => {
        this.$refs['selTableCardUpdate'][0].greet(this.serviceCardListUpdate)
      })
    },
    multipleSelectionServiceCardUpdate (data) {
      this.openServiceCardUpdate = false
      this.serviceCardListUpdate = data
      console.log(this.serviceCardListUpdate)
      this.serviceCardListUpdate.forEach(i => {
        this.$set(i, 'serviceCardNumber', 1)
      })
    },
    handleDeleteserServiceCardUpdate (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.serviceCardListUpdate.splice(val, 1)
      })
    },
    // 升级服务项目
    addServiceItemUpdate () {
      this.$forceUpdate()
      this.openServiceItemUpdate = true
      this.$nextTick(() => {
        this.$refs['selTableItemUpdate'][0].greet(this.serviceItemListUpdate)
      })
    },
    multipleSelectionServiceItemUpdate (data) {
      this.openServiceItemUpdate = false
      this.serviceItemListUpdate = data
      console.log(data)
      this.serviceItemListUpdate.forEach(i => {
        this.$set(i, 'itemNumber', 1)
      })
    },
    handleDeleteserServiceItemUpdate (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.serviceItemListUpdate.splice(val, 1)
      })
    },

    // 权益商品
    addProduct () {
      this.$forceUpdate()
      this.openProduct = true
      this.$nextTick(() => {
        this.$refs['selTableProduct'][0].greet(this.productList)
      })
    },
    multipleSelectionProduct (data) {
      this.openProduct = false
      this.productList = data
      this.productList.forEach(i => {
        this.$set(i, 'productNumber', 1)
      })
    },
    handleDeleteserProduct (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.productList.splice(val, 1)
      })
    },
    // 权益套餐卡
    addServiceCard () {
      this.$forceUpdate()
      this.openServiceCard = true
      this.$nextTick(() => {
        this.$refs['selTableCard'][0].greet(this.serviceCardList)
      })
    },
    multipleSelectionServiceCard (data) {
      console.log(data)

      this.openServiceCard = false
      this.serviceCardList = data
      console.log(this.serviceCardList)

      this.serviceCardList.forEach(i => {
        this.$set(i, 'serviceCardNumber', 1)
      })
    },
    handleDeleteserServiceCard (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.serviceCardList.splice(val, 1)
      })
    },
    // 权益服务项目
    addServiceItem () {
      this.$forceUpdate()
      this.openServiceItem = true
      this.$nextTick(() => {
        this.$refs['selTableItem'][0].greet(this.serviceItemList)
      })
    },
    multipleSelectionServiceItem (data) {
      this.openServiceItem = false
      this.serviceItemList = data
      this.serviceItemList.forEach(i => {
        this.$set(i, 'itemNumber', 1)
      })
      console.log(this.serviceItemList)
    },
    handleDeleteserServiceItem (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.serviceItemList.splice(val, 1)
      })
    },


    //输入框失去焦点事件
    privilegeOnInputBlur (privilegeValue) {
      let reg = /^((0\.[1-9]{1})|(([1-9]{1})(\.\d{1})?))$/
      if (!reg.test(privilegeValue)) {
        this.$message.error('请输入整数或小数后一位')
      }
    },
    upgradeOnInputBlur (privilegeValue) {
      let reg = /^[0-9]{1,8}$/
      if (!reg.test(privilegeValue)) {
        this.$message.error('请输入八位整数')
      }
    },
    privilegeOnInputBlurs (privilegeValue) {
      let reg = /^[0-9]{0,8}$/
      if (!reg.test(privilegeValue)) {
        this.$message.error('请输入正整数,最多8位')
      }
    },
    multipleSelection (data) {
      this.openR = false
      this.infoList = data
      this.infoList.forEach(i => {
        this.$set(i, 'giftsNumber', 1)
      })
    },
    multipleSelection2 (data) {
      this.openC = false
      this.infoList2 = data
      this.infoList2.forEach(i => {
        this.$set(i, 'couponNumber', 1)
      })
    },
    toCloseBox () {
      this.openR = false
    },
    toCloseBox2 () {
      this.openC = false
    },
    search () {
      this.privilege()
    },
    more () {
    },
    more2 () {
    },
    handleDeleteser (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.infoList.splice(val, 1)
      })
    },
    handleDeleteser2 (val, row) {
      // 模态框删除按钮
      this.$confirm('是否确认删除本条数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.infoList2.splice(val, 1)
      })
    },
    addcoupon () {
      this.$forceUpdate()
      this.openC = true
      this.$nextTick(() => {
        this.$refs['selTable2'][0].greet2(this.infoList2)
      })
    },
    addgift () {
      this.$forceUpdate()
      this.openR = true
      this.$nextTick(() => {
        this.$refs['selTable'][0].greet(this.infoList)
      })

    },
    editLevelDia () {
      this.reset()
    },
    unit (platformUnit) {
      for (let i = 0; i < this.checkExceptRisk.length; i++) {
        if (this.checkExceptRisk[i].platformUnit == platformUnit) {
          return true
        }
      }
    },
    unit2 (platformUnit) {
      for (let i = 0; i < this.checkExceptRisk.length; i++) {
        if (this.checkExceptRisk[i].platformUnit == platformUnit) {
          return true
        }
      }
    },
    privilege (val, item, index, hashs) {
      if (item != null) {
        if (val == true) {
          if (item.privleageName == 'coupon') {
            item.privilegeValue = item.privleageName
            this.coupon = true
          }
          if (item.privleageName == 'good') {
            item.privilegeValue = item.privleageName
            this.product = true
          }
          if (item.privleageName == 'proboxCard') {
            item.privilegeValue = item.privleageName
            this.serviceCard = true
          }
          if (item.privleageName == 'item') {
            item.privilegeValue = item.privleageName
            this.serviceItem = true
          }
          this.checkExceptRisk.forEach((riskItem) => {
            if (riskItem.privleageName == item.privleageName) {
              riskItem.privilegeStatus = true
            }
          })
        }
        if (val == false) {
          if (item.privleageName == 'coupon') {
            item.privilegeValue = item.privleageName
            item.privilegeStatus = false
            this.infoList2 = []
            this.coupon = false
          }
          if (item.privleageName == 'good') {
            item.privilegeValue = item.privleageName
            this.product = false
            item.privilegeStatus = false
            this.productList = []
          }
          if (item.privleageName == 'proboxCard') {
            item.privilegeValue = item.privleageName
            this.serviceCard = false
            item.privilegeStatus = false
            this.serviceCardList = []
          }
          if (item.privleageName == 'item') {
            item.privilegeValue = item.privleageName
            this.serviceItem = false
            item.privilegeStatus = false
            this.serviceItemList = []
          }
          this.checkExceptRisk.forEach((riskItem) => {
            if (riskItem.privleageName == item.privleageName) {
              riskItem.privilegeStatus = false
            }
          })
        }
        item.privilegeStatus = val
        for (let i = 0; i < this.checkExceptRisk.length; i++) {
          if (this.checkExceptRisk[i].privleageName === item.privleageName) {
            this.checkExceptRisk[i] = item
          }
        }
      }
    },
    privilege2 (val, item, index, listPrivilegedatas) {
      if (item != null) {
        if (val == true) {
          if (item.privleageName == 'couponUpdate') {
            item.privilegeValue = item.privleageName
          }
          if (item.privleageName == 'goodUpdate') {
            item.privilegeValue = item.privleageName
          }
          if (item.privleageName == 'proboxCardUpdate') {
            item.privilegeValue = item.privleageName
          }
          if (item.privleageName == 'itemUpdate') {
            item.privilegeValue = item.privleageName
          }



          this.checkExceptRisk.forEach((riskItem) => {
            if (riskItem.privleageName == item.privleageName) {
              riskItem.privilegeStatus = true
            }
          })
          // this.checkExceptRisk.push(item);
        }
        if (val == false) {
          if (item.privleageName == 'couponUpdate') {
            item.privilegeStatus = false
            item.privilegeValue = item.privleageName
            this.infoList2Update = []

          }
          if (item.privleageName == 'goodUpdate') {
            item.privilegeValue = item.privleageName
            item.privilegeStatus = false
            this.productListUpdate = []
          }
          if (item.privleageName == 'proboxCardUpdate') {
            item.privilegeValue = item.privleageName
            item.privilegeStatus = false
            this.serviceCardListUpdate = []
          }
          if (item.privleageName == 'itemUpdate') {
            item.privilegeValue = item.privleageName
            item.privilegeStatus = false
            this.serviceItemListUpdate = []
          }

          for (let i = 0; i < this.checkExceptRisk.length; i++) {
            if (item == this.checkExceptRisk[i]) {
              if (this.checkExceptRisk[i].platformUnit == this.unitss) {
                this.unitss = null
              }
              // this.checkExceptRisk.splice(i, 1);
            }
          }

          this.checkExceptRisk.forEach((riskItem) => {
            if (riskItem.privleageName == item.privleageName) {
              riskItem.privilegeStatus = false
            }
          })

          console.log(this.checkExceptRisk)
        }
        item.privilegeStatus = val
        for (let i = 0; i < this.checkExceptRisk.length; i++) {
          if (this.checkExceptRisk[i].privleageName === item.privleageName) {
            this.checkExceptRisk[i] = item
          }
        }
      }
    },
    // 表单重置
    reset () {
      this.levelColor = null
      this.form = {
        levelId: null,
        platformId: null,
        customerGrade: null,
        customerPattern: null,
        levelName: null,
        levelColor: null,
        levelIcon: null,
        minScore: null,
        fansNumber: null,
        performance: null,
        customerNumber: null,
        ruleId: null,
        dataStatus: '0',
        createTime: null,
        updateTime: null,
        createUser: null,
        updateUser: null,
        gradeprivilegeId: null,
        startStatus: '0',
        directPointsPoints: null,
        indirectPointsPoints: null,
        selfbuyPointsPoints: null
      }
      this.resetForm('form')
    },
    getPrivileageInfo () {
      PrivileageInfo().then((res) => {
        this.form = res
        this.hash = []
        this.listPrivilegedata = []
        res.customerLevelPrivleageVos.forEach((item) => {
          if (item.isUpgrade == 0) {
            this.hash.push(item)
          } else {
            this.listPrivilegedata.push(item)
          }
          this.checkExceptRisk.push(item)
        })
        console.log(this.hash)

      })
    },
    getPrivileageInfoUpdate (customerLevelPrivleageVos) {
      PrivileageInfo().then((res) => {
        this.form = res
        this.hash = []
        this.listPrivilegedata = []
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 0) {
            this.hash.push(this.form.customerLevelPrivleageVos[i])
          }
        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 1) {
            this.listPrivilegedata.push(this.form.customerLevelPrivleageVos[i])
          }
        }
      })
    },
    handCloseDetail () {
      this.viewOpen = false
      this.showData = []
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset()
      const levelId = row.levelId || this.ids
      levelInfoDetail(levelId).then((response) => {
        console.log(response.customerLevel, '回显数据')
        this.form = response.customerLevel
        this.bgcolor = this.form.levelColor
        this.openE = true
        this.title = '修改客户等级'
        this.hash = []
        this.listPrivilegedata = []
        let giveobjs = new Array()
        let giveobjs2 = new Array()
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (
            this.form.customerLevelPrivleageVos[i].levelPrivileageGives != null
          ) {
            let giveList =
              this.form.customerLevelPrivleageVos[i].levelPrivileageGives
            giveList.forEach((item) => {
              if (item.giveType == 'coupon') {
                let giveobj2 = new Object()
                giveobj2.couponTypeName = item.giveName
                giveobj2.couponUid = item.giveGiftId
                giveobj2.couponNumber = item.giveNumber
                giveobj2.stock = item.giveSumNumber
                giveobjs2.push(giveobj2)
              }
              if (item.giveType == 'gift') {
                let giveobj = new Object()
                giveobj.giftName = item.giveName
                giveobj.giftUid = item.giveGiftId
                giveobj.giftsNumber = item.giveNumber
                giveobj.stockNumber = item.giveSumNumber
                giveobjs.push(giveobj)
              }
            })
            this.infoList2 = giveobjs2
            this.infoList = giveobjs
          }
        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          this.checkExceptRisk.push(this.form.customerLevelPrivleageVos[i])
          if (this.checkExceptRisk[i].privilegeStatus == true) {
            if (this.checkExceptRisk[i].privleageName == 'coupon') {
              this.coupon = true
            }
            if (this.checkExceptRisk[i].privleageName == 'gift') {
              this.Giftgiving = true
            }
          }
        }

        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 0) {
            this.hash.push(this.form.customerLevelPrivleageVos[i])
          }
        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 1) {
            this.listPrivilegedata.push(this.form.customerLevelPrivleageVos[i])
          }
        }
      })
    },
    startStatusUpdate (row, statu) {
      let text
      if (statu === 0) {
        text = '停用'
      }
      if (statu === 1) {
        text = '启动'
      }
      let levelName = row.levelName
      this.$confirm(
        '是否"' + text + '"名称为"' + levelName + '的等级?',
        '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
      )
        .then(function () {
          let startStatus = statu
          return UpdateStartStatus(row.levelId, startStatus)
        })
        .then(() => {
          this.getList()
          this.msgSuccess(text + '成功')
        })
    },
    getNumber (k, i, idx, type) {
      i = parseInt(i)
      k = parseInt(k)
      if (i > k) {
        if (type == '1') {
          this.productList[idx].productNumber = 1
        } else {
          this.productListUpdate[idx].productNumber = 1
        }
        this.msgError('赠品数不能大商品总数')

      }
    },
    getCouponNumber (k, i, idx, type) {
      i = parseInt(i)
      k = parseInt(k)
      if (i > k) {
        if (type == '1') {
          this.infoList2[idx].couponNumber = 1

        } else {
          this.infoList2Update[idx].couponNumber = 1

        }
        this.msgError('赠送数不能大于优惠券总数')
      }
    },
    //跳转自定义权益
    skipPrivileage () {
      this.$router.push('/privilege/data/')
    },
    /** 提交按钮 */
    submitForm () {
      let errCount = 0;
      this.checkExceptRisk.forEach((item) => {
        if (item.privilegeStatus == true) {
          let value = item.privilegeValue
          let reg = ''
          let msg = ''
          if (item.privleageName == 'discount_') {
            reg = /^((0\.[1-9]{1})|(([1-9]{1})(\.\d{1})?))$/
            msg = item.privleageShowName + ':输入错误,请输入正确的折扣'
          } else if (item.privleageName == 'freeShipping' || item.privleageName == 'points') {
            reg = /^[0-9]{1,8}$/
            msg = item.privleageShowName + ':输入错误,请输入八位整数'
          }
          if (reg != '') {
            if (!reg.test(value)) {
              errCount++;

              if (errCount == 1) {
                this.$message.error(msg)
              }

            }
          }

        }
      })

      if (errCount == 0) {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            let CustomerLevelVo = this.form
            // CustomerLevelVo.directPointsPoints = this.form.directPointsPointsStr
            // CustomerLevelVo.indirectPointsPoints = this.form.indirectPointsPointsStr
            // CustomerLevelVo.selfbuyPointsPoints = this.form.selfbuyPointsPointsStr
            CustomerLevelVo.customerPattern = 0
            let caedFace = this.form.caedFace
            if (caedFace == undefined) {
              caedFace = '0'
            }
            CustomerLevelVo.caedFace = caedFace
            if (
              CustomerLevelVo.levelColor == null &&
              CustomerLevelVo.levelColor == '' &&
              CustomerLevelVo.levelImage == null &&
              CustomerLevelVo.levelImage == ''
            ) {
              CustomerLevelVo.levelColor = '#87CEEB'
            }
            CustomerLevelVo.levelColor = this.bgcolor
            CustomerLevelVo.levelImage = this.form.levelImage

            Vue.set(CustomerLevelVo, 'customerPrivileges', this.checkExceptRisk)

            CustomerLevelVo.customerPrivileges.forEach((item) => {
              let giveobjs = new Array()
              if (item.privleageName == 'coupon') {
                if (item.privilegeStatus == true) {
                  let privleageName = item.privleageName
                  this.infoList2.forEach((infoItem) => {
                    let giveobj = new Object()
                    giveobj.giveName = infoItem.couponName
                    giveobj.giveGiftId = infoItem.couponUid
                    giveobj.giveNumber = infoItem.couponNumber
                    giveobj.giveSumNumber = infoItem.stock
                    giveobj.giveType = privleageName
                    giveobjs.push(giveobj)
                  })
                  Vue.set(item, 'levelPrivileageGives', giveobjs)
                } else {
                  Vue.set(item, 'levelPrivileageGives', null)
                }
              } else if (item.privleageName == 'couponUpdate') {
                if (item.privilegeStatus == true) {
                  let privleageName = item.privleageName
                  this.infoList2Update.forEach((infoItem) => {
                    let giveobj = new Object()
                    giveobj.giveName = infoItem.couponName
                    giveobj.giveGiftId = infoItem.couponUid
                    giveobj.giveNumber = infoItem.couponNumber
                    giveobj.giveSumNumber = infoItem.stock
                    giveobj.giveType = privleageName
                    giveobjs.push(giveobj)
                  })
                  Vue.set(item, 'levelPrivileageGives', giveobjs)
                } else {
                  Vue.set(item, 'levelPrivileageGives', null)
                }
              } else if (item.privleageName == 'good') {
                if (item.privilegeStatus == true) {
                  let privleageName = item.privleageName
                  this.productList.forEach((infoItem) => {
                    let giveobj = new Object()
                    giveobj.giveName = infoItem.productName
                    giveobj.giveGiftId = infoItem.productUid
                    giveobj.giveNumber = infoItem.productNumber
                    giveobj.giveSumNumber = infoItem.stockNumber
                    giveobj.giveType = privleageName
                    giveobjs.push(giveobj)
                  })
                  Vue.set(item, 'levelPrivileageGives', giveobjs)
                } else {
                  Vue.set(item, 'levelPrivileageGives', null)
                }
              } else if (item.privleageName == 'goodUpdate') {
                if (item.privilegeStatus == true) {
                  let privleageName = item.privleageName
                  this.productListUpdate.forEach((infoItem) => {
                    let giveobj = new Object()
                    giveobj.giveName = infoItem.productName
                    giveobj.giveGiftId = infoItem.productUid
                    giveobj.giveNumber = infoItem.productNumber
                    giveobj.giveSumNumber = infoItem.stockNumber
                    giveobj.giveType = privleageName
                    giveobjs.push(giveobj)
                  })
                  Vue.set(item, 'levelPrivileageGives', giveobjs)
                } else {
                  Vue.set(item, 'levelPrivileageGives', null)
                }
              } else if (item.privleageName == 'proboxCard') {
                if (item.privilegeStatus == true) {
                  let privleageName = item.privleageName
                  this.serviceCardList.forEach((infoItem) => {
                    let giveobj = new Object()
                    giveobj.giveName = infoItem.cardName
                    giveobj.giveGiftId = infoItem.cardId
                    giveobj.giveNumber = infoItem.serviceCardNumber
                    giveobj.giveSumNumber = 0
                    giveobj.giveType = privleageName
                    giveobjs.push(giveobj)
                  })
                  Vue.set(item, 'levelPrivileageGives', giveobjs)
                } else {
                  Vue.set(item, 'levelPrivileageGives', null)
                }
              } else if (item.privleageName == 'proboxCardUpdate') {
                if (item.privilegeStatus == true) {
                  let privleageName = item.privleageName
                  this.serviceCardListUpdate.forEach((infoItem) => {
                    let giveobj = new Object()
                    giveobj.giveName = infoItem.cardName
                    giveobj.giveGiftId = infoItem.cardId
                    giveobj.giveNumber = infoItem.serviceCardNumber
                    giveobj.giveSumNumber = 0
                    giveobj.giveType = privleageName
                    giveobjs.push(giveobj)
                  })
                  Vue.set(item, 'levelPrivileageGives', giveobjs)
                } else {
                  Vue.set(item, 'levelPrivileageGives', null)
                }
              } else if (item.privleageName == 'item') {
                if (item.privilegeStatus == true) {
                  let privleageName = item.privleageName
                  this.serviceItemList.forEach((infoItem) => {
                    let giveobj = new Object()
                    giveobj.giveName = infoItem.itemName
                    giveobj.giveGiftId = infoItem.itemId
                    giveobj.giveNumber = infoItem.itemNumber
                    giveobj.giveSumNumber = 0
                    giveobj.giveType = privleageName
                    giveobjs.push(giveobj)
                  })
                  Vue.set(item, 'levelPrivileageGives', giveobjs)
                } else {
                  Vue.set(item, 'levelPrivileageGives', null)
                }
              } else if (item.privleageName == 'itemUpdate') {
                if (item.privilegeStatus == true) {
                  let privleageName = item.privleageName
                  this.serviceItemListUpdate.forEach((infoItem) => {
                    let giveobj = new Object()
                    giveobj.giveName = infoItem.itemName
                    giveobj.giveGiftId = infoItem.itemId
                    giveobj.giveNumber = infoItem.itemNumber
                    giveobj.giveSumNumber = 0
                    giveobj.giveType = privleageName
                    giveobjs.push(giveobj)
                  })
                  Vue.set(item, 'levelPrivileageGives', giveobjs)
                } else {
                  Vue.set(item, 'levelPrivileageGives', null)
                }
              }
            })

            console.log(CustomerLevelVo, '显示数据')

            if (this.form.levelId != null) {
              console.log(CustomerLevelVo, '修改数据')
              UpdateLevelPrivileageInfo(CustomerLevelVo).then((response) => {
                this.msgSuccess('修改成功')
                CustomerLevelVo = null
                this.openE = false
                this.colseLevel()
              })
            } else {
              let Privileges = new Array()
              CustomerLevelVo.customerPrivileges.forEach((item) => {
                if (item.privilegeStatus == true) {
                  Privileges.push(item)
                }
              })
              CustomerLevelVo.customerPrivileges = []
              Privileges.forEach((item) => {
                CustomerLevelVo.customerPrivileges.push(item)
              })
              console.log(CustomerLevelVo, '添加数据')
              saveLevelPrivileageInfo(CustomerLevelVo).then((response) => {
                this.msgSuccess('新增成功')
                CustomerLevelVo = null
                this.openE = false
                this.colseLevel()
              })
            }
          }
        })
      }

    },
    // 上传图片之前
    beforeUpload (file) {
      let _self = this
      return new Promise((resolve, reject) => {
        getUploadToken()
          .then((response) => {
            _self.uploadData.key = response.data.key
            _self.uploadData.token = response.data.token
            _self.upload_domain = response.data.domain
            resolve(true)
          })
          .catch((err) => {
            reject(false)
          })
      })
    },
    beforeRemove (file, fileList) {
      return new Promise((resolve, reject) => {
        this.$confirm(`是否删除该图片？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.previewImg = ''
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            resolve()
            return true
          })
          .catch((err) => {
            reject(err)
            return false
          })
      })
    },
    handleRemove (file, fileList) {
      this.previewImg = ''
    },
    handleSuccess (response, file, fileList) {
      this.previewImg = this.upload_domain + response.key
    },
    // 取消按钮
    Formcancel () {
      this.colseLevel()
    },
    colseLevel () {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.push({
        path: '/customer/level',
        query: {
          t: Date.now()
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
#container {
  width: 100%;
  height: 50%;
}

#photo {
  float: left;
  width: 70%;
}

#content {
  float: right;
  width: 30%;
}

.product-header {
  font-size: 18px;
  margin-bottom: 20px;
}

.product-div {
  background-color: #fff;
  position: relative;
  padding: 30px;
  border: 1px solid #eee;
  border-radius: 10px;
  width: 1200px;
  margin: 30px auto;
}

.product-div-two {
  background-color: #fff;
  position: relative;
  padding: 20px;
  border: 1px solid #eee;
  border-radius: 10px;
  width: 1200px;
  margin: 30px auto;
}

.product-div-three {
  background-color: #fff;
  position: relative;
  padding: 20px;
  border: 1px solid #eee;
  border-radius: 10px;
  width: 1200px;
  margin: 30px auto 100px;
}

.place-font {
  color: #999;
  font-size: 13px;
  position: relative;
}

.dw {
  position: fixed;
  bottom: 0;
  z-index: 10;
  left: 0;
  width: 100%;
  height: 68px;
  padding-left: 120px;
  box-shadow: 0 -2px 8px rgb(200 201 204 / 20%);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.div-img {
  display: none;
}

.div-text {
  margin: 22px 0px 12px 120px;
  color: #2656bd;
  cursor: pointer;
  font-size: 13px;
}

.bgcard {
  width: 253px;
  height: 165px;
  border-radius: 15px;
  position: absolute;
  top: 15%;
  right: 5%;
}

.font-a {
  font-size: 22px;
  font-weight: 900;
  color: #ffffff;
  margin: 20px 0 0 20px;
}

.font-b {
  font-size: 12px;
  color: #ffffff;
  margin: 0px 0 0 20px;
}

.font-b span {
  font-size: 24px;
  font-weight: 700;
}

.font-c {
  width: 89%;
  border: 1px solid #fff;
  margin: 20px 0 0 20px;
}

.itemyanse {
  width: 100%;
  height: 100%;
  display: flex;
  flex: 1;
  margin-top: 5px;
}

.bgyanse {
  width: 20%;
  margin-right: 5px;
}

// .elradio {
//   margin-top: 12px;
// }
.formitem {
  width: 100%;
  height: 100%;
  position: relative;
  top: -30px;
}

.formitem-p {
  font-size: 20px;
}

.qy {
  font-size: 20px;
}

.Unitdiv {
  display: inline-block;
  width: 30px;
  height: 29px;
  border-left: 1px solid #dcdee0;
  border-right: 1px solid #dcdee0;
  position: relative;
  top: 0;
  right: 31px;
  background-color: #f7f8fa;
  text-align: center;
  line-height: 29px;
}

.el-input {
  width: 120px;
}

.selectgift {
  margin-top: 10px;
}

.el-checkbox {
  margin-bottom: 10px;
}

.GiftBag {
  position: relative;
}

.inputcolumn {
  // position: absolute;
  // top: 10px;
  // right: 25px;
  // margin-left: 80%;
  .el-input {
    width: 60px;
  }
}

.el-checkbox {
  width: 70px;
}

.couponGift {
  width: 100px;
  height: 30px;
  font-size: 14px;
  color: rgb(0, 175, 255);
  display: inline-block;
  margin-left: 10px;
}

.block {
  padding: 30px 0;
  text-align: center;
  display: inline-block;
  vertical-align: top;
  margin-top: 1%;
  margin-left: -9%;
}

.app-container {
  background-color: #f7f8fa;
  padding: 20px;
}

.font-normal1 {
  font-size: 12px;
  color: #84868a;
  margin-top: -5px;
}

.font-normal {
  font-size: 12px;
  color: #84868a;
  margin-top: -6px;
}

.div-title {
  background-color: rgb(242, 246, 252);
  margin: 15px;
  padding: 10px 10px 10px 10px;
}

// .dw {
//   border: 1px;
//   position: fixed;
//   bottom: 0px;
//   background-color: #f2f6fc;
//   width: 100%;
//   height: 55px;
// }

.descText {
  color: var(--theme-stroke-3, #969799);
  line-height: 14px;
  font-size: 12px;
  margin-top: 10px;
  margin-bottom: 0;
}

.titleText {
  line-height: 14px;
  font-size: 14px;
  margin-top: 10px;
  margin-bottom: 0;
}

.channelClass {
  border: 1px solid #e5e5e5;
  padding: 20px;
  width: 450px;
  height: 300px;
  float: left;
  margin-left: 20px;
  margin-top: 20px;
}

.channelConten {
  border: 1px dotted #e5e5e5;
  padding: 25px 10px;
  height: 170px;
  text-align: center;
  min-height: 110px;
  box-sizing: border-box;
  display: -ms-flexbox;
  display: flex;
  margin-top: 10px;
  -ms-flex-align: center;
  align-items: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.descIcon {
  font-size: 40px;
  line-height: 40px;
  font-weight: 200;
  color: #155bd4;
}

// .el-input {
//   width: 200px;
// }

/deep/ .el-upload--picture-card {
  width: 60px;
  height: 60px;
}

/deep/ .el-upload {
  width: 60px;
  height: 60px;
  line-height: 60px;
  margin-top: 10px;
}

/deep/ .el-upload-list--picture-card .el-upload-list__item {
  width: 60px;
  height: 60px;
  line-height: 60px;
}

/deep/ .el-upload-list--picture-card .el-upload-list__item-thumbnail {
  width: 60px;
  height: 60px;
  line-height: 60px;
}

/deep/ .avatar {
  width: 60px;
  height: 60px;
}

.el-icon-plus {
  font-size: 14px;
}
</style>
